<script setup lang="ts">
// 点击编辑
import {onMounted, ref} from "vue";
import myAxios from "../plugins/myAxios.ts";
import TeamCardList from "../components/TeamCardList.vue";


const teamList = ref([]);

onMounted(async () => {
  await doUserJoinTeam();
})


const doUserManageTeam = async () => {
  const res = await myAxios.post('/team/my/page/manage', {
    current: 1,
    size: 10
  });
  if (res.code === 0) {
    teamList.value = res.data.records
  }
}

const doUserJoinTeam = async () => {
  const res = await myAxios.post('/team/my/page/join', {
    current: 1,
    size: 10
  });
  if (res.code === 0) {
    teamList.value = res.data.records
  }
}

const activeName = ref('1');
const onClickTab = async (index: string) => {
  activeName.value = index.name;
  console.log(activeName.value)
  if (activeName.value === '1') {
    doUserJoinTeam();
  } else {
    doUserManageTeam();
  }
}

</script>

<template>
  <template v-if="teamList">
    <van-tabs v-model="activeName" @click-tab="onClickTab">
      <van-tab title="我加入的" name="1">
        <TeamCardList :team-list="teamList"/>
      </van-tab>
      <van-tab title="我管理的" name="2">
        <TeamCardList :team-list="teamList"/>
      </van-tab>
    </van-tabs>
  </template>
</template>

<style scoped>

</style>